package com.ruoyi.common.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.ums.dao.YytUmsMemberCollectShopMapper;
import com.ruoyi.common.ums.entity.YytUmsMemberCollectShop;
import com.ruoyi.common.ums.service.YytUmsMemberCollectShopService;
import org.springframework.stereotype.Service;

/**
 * 用户收藏（关注）店铺Service
 *
 * @author tanxingxian
 * @date 2021-12-23 11:31
 */
@Service
public class YytUmsMemberCollectShopServiceImpl extends ServiceImpl<YytUmsMemberCollectShopMapper, YytUmsMemberCollectShop>
        implements YytUmsMemberCollectShopService {

    /**
     * 用户关注（取消关注）店铺
     */
    @Override
    public String follow(YytUmsMemberCollectShop collectShop) {
        LambdaQueryWrapper<YytUmsMemberCollectShop> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(YytUmsMemberCollectShop::getMemberId, collectShop.getMemberId());
        wrapper.eq(YytUmsMemberCollectShop::getShopId, collectShop.getShopId());
        YytUmsMemberCollectShop dbCollect = getOne(wrapper);
        if (null != dbCollect) {    // 取消关注
            removeById(dbCollect.getId());
            return "取消关注成功";
        }
        save(collectShop);
        return "关注成功";
    }
}
